package com.ehotting.edsta.csharpServer.controller;

import com.ehotting.eaf.core.domain.R;
import com.ehotting.eaf.core.utils.poi.ExcelUtil;
import com.ehotting.eaf.core.web.controller.BaseController;
import com.ehotting.eaf.core.web.page.TableDataInfo;
import com.ehotting.edsta.common.log.annotation.Log;
import com.ehotting.edsta.common.log.enums.BusinessType;
import com.ehotting.edsta.csharpServer.domain.ProjectInfo;
import com.ehotting.edsta.csharpServer.domain.vo.ProjectInfoRes;
import com.ehotting.edsta.csharpServer.domain.vo.ProjectInfoVo;
import com.ehotting.edsta.csharpServer.service.IProjectInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 工程信息Controller
 * 
 * @author edsta
 * @date 2023-04-11
 */
@RestController
@RequestMapping("/info")
@Api(tags = "ProjectInfoController",description = "工程管理相关接口")
public class ProjectInfoController extends BaseController {
    @Autowired
    private IProjectInfoService projectInfoService;

    /**
     * 查询工程信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ProjectInfo projectInfo) {
        startPage();
        List<ProjectInfo> list = projectInfoService.selectProjectInfoList(projectInfo);
        return getDataTable(list);
    }

    /**
     * 查询工程信息列表
     */
    @GetMapping("/listTable")
    public TableDataInfo listTable(ProjectInfo projectInfo) {
        startPage();
        List<ProjectInfoRes> list = projectInfoService.getProjectInfoList(projectInfo);
        return getDataTable(list);
    }

    /**
     * 导出工程信息列表
     */
    @Log(title = "工程信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectInfo projectInfo) throws IOException {
        List<ProjectInfo> list = projectInfoService.selectProjectInfoList(projectInfo);
        ExcelUtil<ProjectInfo> util = new ExcelUtil<ProjectInfo>(ProjectInfo.class);
        util.exportExcel(response, list, "工程信息数据");
    }

    /**
     * 获取工程信息详细信息
     * @return
     */
    @Log(title = "工程信息详情", businessType = BusinessType.GET_DATA)
    @ApiOperation("根据id获取工程信息详细信息")
    @GetMapping(value = "/{id}")
    public R<ProjectInfo> getInfo(@PathVariable("id") Long id) {
        return R.ok(projectInfoService.selectProjectInfoById(id));
    }

    /**
     * 新增工程信息
     * @return
     */
    @ApiOperation("新增工程信息")
    @Log(title = "工程信息", businessType = BusinessType.INSERT)
    @PostMapping
    public R<ProjectInfo> add(@RequestBody ProjectInfoVo projectInfoVo) {
        ProjectInfo data = projectInfoService.insertProjectInfo(projectInfoVo);
        return R.ok(data);
    }

    /**
     * 修改工程信息
     * @return
     */
    @Log(title = "工程信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ApiOperation("修改工程信息")
    public R<Integer> edit(@RequestBody ProjectInfo projectInfo) {
        return R.ok(projectInfoService.updateProjectInfo(projectInfo));
    }

    /**
     * 删除工程信息
     * @return
     */
    @ApiOperation("删除工程信息")
    @Log(title = "工程信息", businessType = BusinessType.DELETE)
	@GetMapping("/delete/{ids}")
    public R<Integer> remove(@PathVariable Long[] ids) {
        return R.ok(projectInfoService.deleteProjectInfoByIds(ids));
    }

    @Log(title = "根据用户查询所有工程列表", businessType = BusinessType.OTHER)
    @ApiOperation("根据用户查询所有工程列表")
    @GetMapping("/getListByUser")
    public R<List<ProjectInfo>> getListByUser(){
        return R.ok(projectInfoService.selectProjectInfoListByUser());
    }
}
